package com.example.traning.web.config;


import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author lei yu
 * @since 2025/04/28
 */
@Configuration
@EnableConfigurationProperties(MyKnife4jProperties.class)
public class Knife4jConfig {

    // ========== 全局 OpenAPI 配置 ==========

    @Bean
    public OpenAPI createApi(MyKnife4jProperties properties) {
        return new OpenAPI()
                .info(buildInfo(properties));
    }

    private Info buildInfo(MyKnife4jProperties properties) {
        return new Info()
                .title(properties.getTitle())
                .description(properties.getDescription())
                .version(properties.getVersion())
                .contact(new Contact().name(properties.getName()).url(properties.getUrl()).email(properties.getEmail()))
                .license(new License().url(properties.getUrl()).name(properties.getName()));
    }

}
